<script setup lang="ts">
import { Search, Close, Plus,Edit,Delete} from "@element-plus/icons-vue"
import useUserTable from '@/composables/user/useUserTable';
import useUser from "@/composables/user/useUser";
import AddUser from './AddUser.vue'
const { listParam, getList, resetBtn, searchBtn, tableList ,sizeChange,currentChange,tableHeight} = useUserTable();//表格相关的操作
const { addBtn, deleteBtn, editBtn, addRef } = useUser(getList) //增删改查的操作
</script>

<template>
  <el-main>
    <el-form :model="listParam" label-width="80px" :inline="true" size="default">
      <el-form-item>
        <el-input v-model="listParam.name" placeholder="请输入姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="listParam.phone" placeholder="请输入电话"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button :icon="Search" @click="searchBtn">搜索</el-button>
        <el-button :icon="Close" type="danger" plain @click="resetBtn">重置</el-button>
        <el-button type="primary" :icon="Plus" @click="addBtn">新增</el-button>
      </el-form-item>
    </el-form>
    <!-- 用户列表 -->
    <el-table :height="tableHeight" :data="tableList" border stripe>
      <el-table-column label="姓名" prop="name"></el-table-column>
      <el-table-column label="性别" prop="sex">
        <template #default="scope">
          <el-tag v-if="scope.row.sex == '0'" type='primary' size="default">男</el-tag>
          <el-tag v-else type="danger" size="default">女</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="电话" prop="phone"></el-table-column>
      <el-table-column label="邮箱" prop="email"></el-table-column>
      <el-table-column label="操作" width="230">
        <template #default="scope">
          <el-button type="primary" :icon="Edit" size="default" @click="editBtn(scope.row)" >编辑</el-button>
          <el-button type="danger"  :icon="Delete"  size="default" @click="deleteBtn(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChange"
      @current-change="currentChange"
      :current-page.sync="listParam.currentPage"
      :page-sizes="[10,20, 40, 80, 100]"
      :page-size="listParam.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="listParam.total" background>
      >
    </el-pagination>
    
  </el-main>
  <!-- 新增和编辑弹框 -->
  <AddUser ref="addRef" @onFresh="getList"></AddUser>
</template>

<style scoped></style>